package com.sg.file.manager.provider;

import com.sg.file.manager.api.IFileInfoService;
import com.sg.file.manager.repository.FileRepository;
import com.sg.file.manager.repository.pojo.FileInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Optional;

/**
 * Created by asus on 2018/7/16.
 */
@Service
public class FileInfoService implements IFileInfoService {
    @Autowired
    private FileRepository fileRepository;
    @Override
    public FileInfo getById(String id) {
        Optional<FileInfo> optionalFileInfo = fileRepository.findById(id);
        if(optionalFileInfo.isPresent()){
            return optionalFileInfo.get();
        }
        return null;
    }

    @Override
    public FileInfo save(FileInfo fileInfo) {
        return fileRepository.save(fileInfo);
    }

    @Override
    public List<FileInfo> saveAll(List<FileInfo> fileInfo) {
        return fileRepository.saveAll(fileInfo);
    }

    @Override
    public List<FileInfo> queryFiles(List<String> fileIds) {
        return fileRepository.findAllById(fileIds);
    }

    @Override
    public void delete(String fileId) {
        fileRepository.deleteById(fileId);
    }
}
